package com.sbhotel.chotellauncher.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sbhotel.chotellauncher.R;

public class SettingsItemView extends LinearLayout {

    private Context mContext;
    private View mView;
    private TextView titleTv, descTv;
    private ImageView iconIv, moreIv;
    private OnClickListener onClickListener;

    String title, desc = "";
    int iconImageId = 0;

    public SettingsItemView(Context context) {
        this(context, null);
    }

    public SettingsItemView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SettingsItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.item_settings, this, true);
        titleTv = (TextView) mView.findViewById(R.id.tv_title);
        descTv = (TextView) mView.findViewById(R.id.tv_desc);
        iconIv = (ImageView) mView.findViewById(R.id.iv_icon);
        moreIv = (ImageView) mView.findViewById(R.id.iv_more);

        this.setBackgroundResource(R.drawable.settings_menu_selector);

        /*TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.MenuItemLayout);
        setTitleText(a.getString(R.styleable.MenuItemLayout_title_text));
        setHintText(a.getString(R.styleable.MenuItemLayout_hint_text));
        setIconImgId(a.getResourceId(R.styleable.MenuItemLayout_icon_reference, 10000));
        setJumpUrl(a.getString(R.styleable.MenuItemLayout_jump_url));
        divideLineStyle = a.getInt(R.styleable.MenuItemLayout_divide_line_style, NO_LINE);
        setDivideLine(divideLineStyle);*/
    }

    public void setTitle(String title) {
        this.title = title;
        titleTv.setText(title);
    }

    public String getTitle() {
        return this.title;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
        descTv.setText(desc);
    }

    public int getIconImageId() {
        return iconImageId;
    }

    public void setIconImageId(int iconImageId) {
        this.iconImageId = iconImageId;
        iconIv.setImageResource(iconImageId);
    }

    public void hideMoreIcon() {
        moreIv.setVisibility(View.INVISIBLE);
    }

    public void displayMoreIcon() {
        moreIv.setVisibility(View.VISIBLE);
    }

    /*public void setViewOnlickListener(OnClickListener onlickListener) {
        this.onClickListener = onlickListener;
        mView.setOnClickListener(onlickListener);
    }*/
}
